<?php
/**
 * @author Jumper Swordwave
 * date: 2021/04/25
 */
namespace HyperfTest\Cases;

use PHPUnit\Framework\TestCase;

use App\Game\Logic\PokerHelper;

class PokerTest extends TestCase
{
    public function testSend()
    {
        list($hands, $holes) = PokerHelper::send();
        $this->assertCount(3, $hands);
        $this->assertCount(3, $holes);

        foreach($hands as $cards) {
            $this->assertCount(17, $cards);
        }
    }

    public function testCheckOk()
    {
        //测试用例
        $examples = [
            //单张测试
            [[8], [7], true],   //5,4
            [[9], [10], false], //5,5
            [[9], [], true],    //5,

            //对子测试
            [[20,21], [17,18], true],   //8对, 7对
            [[24,25], [41,42], false],  //9对, K对
            [[16,20], [8,9], false],    //7,8 出牌非对子

            //三张不带
            [[16,17,18], [4,5,6], true],    //三张7, 三张4
            [[10,12,13], [8,9,11], false],  //出牌非三张

            //三带一
            [[16,17,18,33], [12,13,15,10], true],   //三张7带J, 三张6还5
            [[9,28,30,31], [5,12,13,14], true],     //三张10还5, 三张5带4
            [[8,10,11,12], [16,25,26,27], false],   //三张5带6, 三张J带Q
            [[4,5,20,21], [32,33,34,37], false],    //非三带一,
            [[4,5,6], [32,33,34,37], false],        //非三带一

            //三带二
            [[28,29,30,37,38], [8,9,17,18,19],true],    //三张10带Q对, 三张7带5对
            [[8,9,24,25,27], [20,21,22,36,37], true],   //三张9带5对, 三张8带Q对
            [[8,9,10,12,13], [24,25,26,32,33], false],  //三张5带6对,三张9带J对
            [[8,9,12,13,20], [24,25,26,32,33], false],  //非三带二
            [[8,9,10,13], [24,25,26,32,33], false],     //非三带二

            //顺子
            [[28,33,36,41,46], [8,12,17,21,26], true],  //10JQKA  56789
            [[4,9,12,17,20], [29,32,38,41,44], false],  //45678 10JQKA
            [[18,21,24,30,32,38,42,44], [12,18,23,24,30,35,39,43], true],   //78910JQKA  678910JQK
            [[21,24,30,32,38,42,44], [12,18,23,24,30,35,39,43], false], //8910JQKA  678910JQK
            [[18,21,24,32,33,38,42,44], [12,18,23,24,30,35,39,43], false],  //非顺子
            [[8,12,17,20], [20,24,28,32,36], false],    //非顺子

            //四带一
            [[8,9,10,11, 16], [4,5,6,7, 18], true],     //四张5带7 四张4带7
            [[12,32,33,34,35], [16,17,18,19, 28], true],    //四张J带6  四张7带10
            [[8,9,10,11,16], [28,29,30,31,32], false],  //四张5带7  四张10带J

            //四带二
            [[8,9,10,11,16,17], [4,5,6,7,32,33], true], //四张5还二张7, 四张4带二张J
            [[8,12,28,29,30,31], [4,5,6,7,24,28], true],//四张10带5,6   四张4带9,10
            [[20,21,22,24,25,26], [4,5,6,7, 44,48], false], //非四带2
            [[20,21,22], [4,5,6,7,44,48], false],   //非四带2

            //连对
            [[24,26,28,29,32,35], [16,17,20,21,25,27], true],   //910J, 789
            [[24,26,28,29,32,35], [20,22,25,27,30,31], true],   //910J, 8910
            [[24,26,28,29,32,35], [25,27,30,31,33,34], false],  //910J, 910J
            [[24,26,28,29,32,35,37,38], [20,22,25,27,30,31,], false],   //910JQ,    8910
            [[24,26,28,29,], [25,27,30,31,33,34], false],   //910,  910J
            
            //飞机不带
            [[17,18,19,21,22,23,], [1,2,3,5,6,7], true],    //78,   34
            [[17,18,19,21,22,23], [24,25,26,29,30,31], false],  //78,   910
            [[17,18,19,28,29,30], [1,2,3,5,6,7], false],    //非飞机
            [[20,21,28,29,40,41,], [1,2,3,4,5,6], false],   //非飞机

            //飞机三带一
            [[17,18,19,21,22,23,36,37], [1,2,3,5,6,7,32,36], true], //78带QQ,   34带JQ
            [[12,17,18,19,21,22,23,28], [1,2,3,5,6,7,32,36], true], //78带610,  34还JQ
            [[0,12,17,18,19,21,22,23], [1,2,3,5,6,7,32,36], true],  //78还36,   34还JQ
            [[8, 12, 17,18,19,21,22,23], [10,24,25,26,29,30,31,32], false], //78带56,   910带5J
            [[17,18,19,28,29,30,40,44], [1,2,3,5,6,7,16,20], false],    //非飞机
            [[20,21,28,29,40,41,49,52], [1,2,3,4,5,6,16,28], false],    //非飞机
            
            //飞机三带二
            [[17,18,19,21,22,23,36,37,44,45], [1,2,3,5,6,7,32,33,38,39], true], //78带Q对A对,   34带JQ对
            [[12,13,17,18,19,21,22,23,28,30], [1,2,3,5,6,7,32,33,38,39], true], //78带610对,    34带JQ对
            [[0,1,12,14,17,18,19,21,22,23], [1,2,3,5,6,7,32,33,38,39], true],   //78还36对,     34带JQ对
            [[8,9,12,14,17,18,19,21,22,23], [10,11,24,25,26,29,30,31,32,34], false], //78带56对       910带5J对
            [[17,18,19,28,29,30,40,44,45], [1,2,3,5,6,7,16,20], false],    //非三带二飞机
            [[16,20,21,28,29,40,41,49,52], [1,2,3,4,5,6,16,28], false],    //非三带二飞机

            //炸弹
            [[8,9,10,11], [4,5,6,7], true], //5炸   4炸
            [[32,33,34,35], [8,12,16,20,24], true], //J炸   顺子
            [[32,33,34,35], [8,10], true], //J炸   对子
            [[32,33,34,35], [44,45,46], true], //J炸   三张
            [[32,33,34,35], [44,45,46,48], true], //J炸   三带一
            [[32,33,34,35], [44,45,46,48, 50], true], //J炸   三带二
            [[32,33,34,35], [44,45,46,47,48], true], //J炸   四带一
            [[32,33,34,35], [44,45,46,47,48,50], true], //J炸   四带二
            [[32,33,34,35], [32,33,37,38,40,42], true], //J炸   连对
            [[32,33,34,35], [44,45,46,47], false], //J炸   A炸
            
            //王炸
            [[52,53], [8,9,10,11], true],     //王炸, 5炸
        ];

        foreach($examples as $item) {
            $result = PokerHelper::checkOuts($item[0], $item[1]);
            \App\Log::info('result', [$item, $result]);
            $this->assertSame($result, $item[2]);
        }
    }
}